const express = require('express');
const router = express.Router();
const DataController = require('../controllers/dataController');
const { authenticateToken, authorizeAdmin } = require('../middleware/auth');
const multer = require('multer');

// 配置文件上传
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, Date.now() + '-' + file.originalname)
  }
});

const upload = multer({ storage: storage });

// 数据导出路由
router.get('/export/goods/csv', authenticateToken, authorizeAdmin, DataController.exportGoodsToCSV);
router.get('/export/inbound/csv', authenticateToken, authorizeAdmin, DataController.exportInboundToCSV);
router.get('/export/outbound/csv', authenticateToken, authorizeAdmin, DataController.exportOutboundToCSV);

// 数据导入路由
router.post('/import/goods/csv', authenticateToken, authorizeAdmin, upload.single('file'), DataController.importGoodsFromCSV);

module.exports = router;